﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using proRFID_DiemDanh.Chung;

namespace proRFID_DiemDanh.GiaoVien
{
    public partial class GiaoVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Load_ddl_Khoa(0);
                Load_RptGiaoVien(0, 0);
            }
        }
        public void Load_ddl_Khoa(int MaKhoa)
        {
            DataTable dt = new DataTable();
            dt = mdGiaoVien.sp_Khoa_DDL();
            ddl_Khoa.DataSource = dt;
            ddl_Khoa.DataValueField = "MAKHOA";
            ddl_Khoa.DataTextField = "TENKHOA";
            ddl_Khoa.DataBind();
        }
        public void Load_RptGiaoVien(int MaGV, int MaKhoa)
        {
            DataTable dt = new DataTable();
            dt = mdGiaoVien.sp_GiaoVien_Select(MaGV, MaKhoa);
            Rpt_GiaoVien.DataSource = dt;
            Rpt_GiaoVien.DataBind();
        }
        string Getmucchon()
        {
            if (string.IsNullOrEmpty(Request["chon"]))
                return "";
            return Request["chon"].ToString();
        }
        void XoaMucChon()
        {
            string[] test = null;
            string Mangchon = Getmucchon();
            char[] c = new char[] { ' ', ',' };
            test = Mangchon.ToString().Split(c);
            DataTable dt = new DataTable();
            lbThongBao.Text = "";
            if (!string.IsNullOrEmpty(Mangchon))
            {
                int i;
                int count = 0;
                for (i = 0; i < test.Length; i++)
                {
                    dt = mdGiaoVien.sp_GiaoVien_Delete(Convert.ToInt32(test[i]));
                    if (dt.Rows[0]["ErrCode"].ToString() == "0")
                        count++;
                }
                if (count > 0)
                    mdMain.OKBox(this, "Đã xóa được " + count + " dòng dữ liệu.", "/GiaoVien/GiaoVien.aspx");
                else
                    mdMain.OKBox(this, "Xóa dữ liệu thất bại!", "/GiaoVien/GiaoVien.aspx");
            }
            else
                lbThongBao.Text = "Chưa chọn mục xóa";
        }

        protected void Imgcmd_Them_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("/GiaoVien/ThemGiaoVien.aspx");
        }

        protected void Imgcmd_XoaGV_Click(object sender, ImageClickEventArgs e)
        {
            XoaMucChon();
        }


        protected void ddl_Khoa_SelectedIndexChanged(object sender, EventArgs e)
        {
            Load_RptGiaoVien(0, Convert.ToInt32(ddl_Khoa.SelectedValue));
        }
    }
}